package com.sq.partner.manager.controller;

import com.sq.partner.manager.service.AochuangService;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.SqlUtil;
import com.sq.partner.manager.util.StrUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/AochuangController")
public class AochuangController {
    @Resource
    AochuangService aochuangService;

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(){
        return "Aochuang/Reconciliation";
    }

    @RequestMapping(value = "/queryAochuangInfo",method = RequestMethod.POST)
    @ResponseBody
    public Page queryAochuangInfo( Integer pageIndex,String polno,
                                       String agencyName,String fileName,String status2,String tradeBeginTime,String tradeEndTime) throws Exception{
        Page page = checkBeforeQuery(pageIndex,polno,agencyName,fileName,status2,tradeBeginTime,tradeEndTime);
        return  aochuangService.queryAochuangInfo(page);
    }
    public Page checkBeforeQuery(Integer pageIndex,String polno,
                                 String agencyName,String fileName,String status2,String tradeBeginTime,String tradeEndTime) throws Exception{
        Page page = new Page();
        Map<String,Object> map = new HashMap<String, Object>();
        if(pageIndex != -1){
            page.setCurrent(pageIndex);
            map = SqlUtil.buildPageMap(page);
        }
        map.put("polno",polno);
        map.put("agency_name",agencyName);
        map.put("file_name",fileName);
        map.put("status2",status2);
        //交易日期
        if(StrUtil.isNotEmpty(tradeBeginTime)){
            tradeBeginTime = tradeBeginTime + "00:00:00";
        }
        if(StrUtil.isNotEmpty(tradeEndTime)){
            tradeEndTime = tradeEndTime + "23:59:59";
        }
        map.put("tradeBeginTime",tradeBeginTime);
        map.put("tradeEndTime",tradeEndTime);

        page.setType(map);
        return page;
    }

    @RequestMapping(value = "/queryOrderDetaiByPolno",method = RequestMethod.GET)
    @ResponseBody
    public List queryOrderDetaiByPolno( @RequestParam String polno) throws Exception{
        List list = aochuangService.queryOrderDetaiByPolno( polno);
        return list;
    }
}
